<?php

namespace app\tripapi\model;

use think\Model;

use think\Db;

class TravelChat extends Model{
	
    public function TravelChatSave($params){
        $output = '';
        $time = time();
        unset($params['adhesive']);unset($params['number']);unset($params['product_name']);unset($params['need_num']);unset($params['quota_scale']);unset($params['demand']);unset($params['need_verify']);
        $customer_type = $params['customer_type'];
        foreach($customer_type as $key => $value){
            $params['customer_type'] = iconv('UTF-8', 'gbk', $value);
        }
        $params['category'] = iconv('UTF-8', 'gbk', '销售');
        $params['customer_src'] = iconv('UTF-8', 'gbk', $params['customer_src']);
        $params['customer_category'] = iconv('UTF-8', 'gbk', $params['customer_category']);
        $params['company'] = iconv('UTF-8', 'gbk', $params['company']);
        $params['talk_type'] = iconv('UTF-8', 'gbk', $params['talk_type']);
        $params['company_place'] = iconv('UTF-8', 'gbk', $params['company_place']);
        $params['customer_trade'] = iconv('UTF-8', 'gbk', $params['customer_trade']);
        $params['customer_place'] = iconv('UTF-8', 'gbk', $params['customer_place']);
        $params['salers'] = iconv('UTF-8', 'gbk', $params['salers']);
        $params['cooper_user'] = iconv('UTF-8', 'gbk', $params['cooper_user']);
        $params['contact1'] = iconv('UTF-8', 'gbk', $params['contact1']);
        $params['contact1_job'] = iconv('UTF-8', 'gbk', $params['contact1_job']);
        $params['customer_address'] = iconv('UTF-8', 'gbk', $params['customer_address']);
        $params['contact2'] = iconv('UTF-8', 'gbk', $params['contact2']);
        $params['contact2_job'] = iconv('UTF-8', 'gbk', $params['contact2_job']);
        $params['customer_all'] = iconv('UTF-8', 'gbk', $params['customer_all']);
        $params['staff_all'] = iconv('UTF-8', 'gbk', $params['staff_all']);
        $params['subject'] = iconv('UTF-8', 'gbk', $params['subject']);
        $params['content1'] = iconv('UTF-8', 'gbk', $params['content1']);
        $params['content2'] = iconv('UTF-8', 'gbk', $params['content2']);
        $params['content3'] = iconv('UTF-8', 'gbk', $params['content3']);
        $params['content4'] = iconv('UTF-8', 'gbk', $params['content4']);
        $params['creator'] = iconv('UTF-8', 'gbk', $params['creator']);
        $params['report_user'] = iconv('UTF-8', 'gbk', $params['report_user']);
        if(!empty($params['action_plan'])){
            $params['action_plan'] = iconv('UTF-8', 'gbk', $params['action_plan']);
        }
        if(!empty($params['conclusion'])){
            $params['conclusion'] = iconv('UTF-8', 'gbk', $params['conclusion']);
        }
        $params['create_time'] = $time;
        $approve = Db::name('approval_proces')->where('department_name', 'like', '%'.iconv('UTF-8','GBK',$params['department']))->select();
        $info = Db::name('new_user')->where('user_name', '=', $approve['0']['step1'])->select();
        $username = GetUserNameByUid($params['creator_id']);
        $username = str_replace(',','',$username);
        if($username == $approve['0']['step1']){
            $params['to_user_step'] = $approve['0']['step1'];
            $params['to_status_step'] = '1';
            $params['to_uid_step'] = $params['creator_id'];
        }else{
            $params['to_user_step'] = $approve['0']['step1'];
            $params['to_status_step'] = '0';
            $params['to_uid_step'] = $info['0']['uid'];
        }
        $params['department'] = iconv('UTF-8','GBK', $params['department']);
        $id = Db::name('travel_chat')->insert($params, false, true);
        $output = CustomergetUserIdByUid($this->GetApproveListByName($params['to_user_step'])).",".'您有一条待审批的销售洽谈单'.","."erp5/public/tripapi/negotiation/index?nids=".$id;
        return array('id' => $id, 'params' => $output);
    }

    public function TravelNotSalerChatSave($params){
        $output = '';
        $time = time();
        $params['category'] = iconv('UTF-8', 'gbk', '非销售');
        $params['customer_category'] = iconv('UTF-8', 'gbk', $params['customer_category']);
        $params['company'] = iconv('UTF-8', 'gbk', $params['company']);
        $params['talk_place'] = iconv('UTF-8', 'gbk', $params['talk_place']);
        $params['customer_all'] = iconv('UTF-8', 'gbk', $params['customer_all']);
        $params['staff_all'] = iconv('UTF-8', 'gbk', $params['staff_all']);
        $params['subject'] = iconv('UTF-8', 'gbk', $params['subject']);
        $params['content1'] = iconv('UTF-8', 'gbk', $params['content1']);
        $params['content2'] = iconv('UTF-8', 'gbk', $params['content2']);
        $params['content3'] = iconv('UTF-8', 'gbk', $params['content3']);
        $params['creator'] = iconv('UTF-8', 'gbk', $params['creator']);
        $params['create_time'] = $time;
        $approve = Db::name('approval_proces')->where('department_name', 'like', '%'.iconv('UTF-8','GBK',$params['department']))->select();
        $info = Db::name('new_user')->where('user_name', '=', $approve['0']['step1'])->select();
        $username = GetUserNameByUid($params['creator_id']);
        $username = str_replace(',','',$username);
        if($username == $approve['0']['step1']){
            $params['to_user_step'] = $approve['0']['step1'];
            $params['to_status_step'] = '1';
            $params['to_uid_step'] = $params['creator_id'];
        }else{
            $params['to_user_step'] = $approve['0']['step1'];
            $params['to_status_step'] = '0';
            $params['to_uid_step'] = $info['0']['uid'];
        }
        $params['department'] = iconv('UTF-8','GBK', $params['department']);
        $id = Db::name('travel_chat')->insert($params, false, true);
        $output = CustomergetUserIdByUid($this->GetApproveListByName($params['to_user_step'])).",".'您有一条待审批的非销售洽谈单'.","."erp5/public/tripapi/negotiation/index?nids=".$id;
        return array('id' => $id, 'params' => $output);
    }

    /*
     * 获取列表
     */
    public function GetList($uid, $data, $nid){
        if($nid == 'null '){
            $res = Db::name('travel_chat')->where(function($query) use ($uid) {
                $query->where('creator_id','=',$uid);
            })->whereor(function($query) use ($uid){
                $query->where('to_uid_step','=',$uid);
            })->whereor(function($query) use ($uid){
                $query->where('to_uid_step1','=',$uid);
            })->whereor(function($query) use ($uid){
                $query->where('to_uid_step2','=',$uid);
            })->select();
            $count = count($res);
            $current_page = $data['page'];
            $startSize = "10";
            $lastSize = $startSize*($current_page - 1);
            $result = Db::name('travel_chat')->where(function($query) use ($uid) {
                $query->where('creator_id','=',$uid);
            })->whereor(function($query) use ($uid){
                $query->where('to_uid_step','=',$uid);
            })->whereor(function($query) use ($uid){
                $query->where('to_uid_step1','=',$uid);
            })->whereor(function($query) use ($uid){
                $query->where('to_uid_step2','=',$uid);
            })->order('id','desc')->limit($lastSize,$startSize)->select();
        }else{
            $res = Db::name('travel_chat')->where(function($query) use ($nid, $uid) {
                $query->where('creator_id','=',$uid)->where('id','=',$nid);
            })->whereor(function($query) use ($nid, $uid){
                $query->where('to_uid_step','=',$uid)->where('id','=',$nid);
            })->whereor(function($query) use ($nid, $uid){
                $query->where('to_uid_step1','=',$uid)->where('id','=',$nid);
            })->whereor(function($query) use ($nid, $uid){
                $query->where('to_uid_step2','=',$uid)->where('id','=',$nid);
            })->select();
            $count = count($res);
            $current_page = $data['page'];
            $startSize = "10";
            $lastSize = $startSize*($current_page - 1);
            $result = Db::name('travel_chat')->where(function($query) use ($nid, $uid) {
                $query->where('creator_id','=',$uid)->where('id','=',$nid);
            })->whereor(function($query) use ($nid, $uid){
                $query->where('to_uid_step','=',$uid)->where('id','=',$nid);
            })->whereor(function($query) use ($nid, $uid){
                $query->where('to_uid_step1','=',$uid)->where('id','=',$nid);
            })->whereor(function($query) use ($nid, $uid){
                $query->where('to_uid_step2','=',$uid)->where('id','=',$nid);
            })->order('id','desc')->limit($lastSize,$startSize)->select();
        }

        foreach($result as $key => $value){
            $result[$key]['category'] = iconv('GBK', 'UTF-8', $value['category']);
            $result[$key]['customer_type'] = iconv('GBK', 'UTF-8', $value['customer_type']);
            $result[$key]['customer_src'] = iconv('GBK', 'UTF-8', $value['customer_src']);
            $result[$key]['customer_category'] = iconv('GBK', 'UTF-8', $value['customer_category']);
            $result[$key]['company'] = iconv('GBK', 'UTF-8', $value['company']);
            $result[$key]['talk_type'] = iconv('GBK', 'UTF-8', $value['talk_type']);
            $result[$key]['company_place'] = iconv('GBK', 'UTF-8', $value['company_place']);
            $result[$key]['customer_trade'] = iconv('GBK', 'UTF-8', $value['customer_trade']);
            $result[$key]['customer_place'] = iconv('GBK', 'UTF-8', $value['customer_place']);
            $result[$key]['salers'] = iconv('GBK', 'UTF-8', $value['salers']);
            $result[$key]['cooper_user'] = iconv('GBK', 'UTF-8', $value['cooper_user']);
            $result[$key]['contact1'] = iconv('GBK', 'UTF-8', $value['contact1']);
            $result[$key]['contact1_job'] = iconv('GBK', 'UTF-8', $value['contact1_job']);
            $result[$key]['customer_address'] = iconv('GBK', 'UTF-8', $value['customer_address']);
            $result[$key]['contact2'] = iconv('GBK', 'UTF-8', $value['contact2']);
            $result[$key]['contact2_job'] = iconv('GBK', 'UTF-8', $value['contact2_job']);
            $result[$key]['customer_all'] = iconv('GBK', 'UTF-8', $value['customer_all']);
            $result[$key]['staff_all'] = iconv('GBK', 'UTF-8', $value['staff_all']);
            $result[$key]['subject'] = iconv('GBK', 'UTF-8', $value['subject']);
            $result[$key]['content1'] = iconv('GBK', 'UTF-8', $value['content1']);
            $result[$key]['content2'] = iconv('GBK', 'UTF-8', $value['content2']);
            $result[$key]['content3'] = iconv('GBK', 'UTF-8', $value['content3']);
            $result[$key]['content4'] = iconv('GBK', 'UTF-8', $value['content4']);
            $result[$key]['report_user'] = iconv('GBK', 'UTF-8', $value['report_user']);
            $result[$key]['creator'] = iconv('GBK', 'UTF-8', $value['creator']);
            $result[$key]['department'] = iconv('GBK', 'UTF-8', $value['department']);
            $result[$key]['talk_place'] = iconv('GBK', 'UTF-8', $value['talk_place']);
            $result[$key]['action_plan'] = iconv('GBK', 'UTF-8', $value['action_plan']);
            $result[$key]['conclusion'] = iconv('GBK', 'UTF-8', $value['conclusion']);
            $result[$key]['to_user_step'] = iconv('GBK', 'UTF-8', $value['to_user_step']);
            $result[$key]['to_user_step1'] = iconv('GBK', 'UTF-8', $value['to_user_step1']);
            $result[$key]['to_user_step2'] = iconv('GBK', 'UTF-8', $value['to_user_step2']);
            $result[$key]['count'] = $count;
            if($value['to_status_step'] == '1' && $value['to_status_step1'] == '1'){
                $result[$key]['status'] = "人事存档";
            }elseif($value['to_status_step'] == '1' && $value['to_status_step1'] == '0'){
                $result[$key]['status'] = "总经理审批中";
            }elseif($value['to_status_step'] == '0' && $value['to_status_step1'] == ''){
                $result[$key]['status'] = "部门审批中";
            }
        }
        return $result;
    }
    /*
     * 删除
     */
    public function ChatDelete($id){
        Db::name('travel_chat')->where('id', '=', $id)->delete();
        return true;
    }

    /*
     *  非销售人员洽谈单编辑页面获取详情
     */
    public function travelnotsaleredit($id){
        $result = Db::name('travel_chat')->where([
            'id'=>['=',$id],
            'category'=>['=',iconv('UTF-8', 'GBK','非销售')]
        ])->select();
        foreach($result as $key => $value){
            $result[$key]['id'] = $value['id'];
            $result[$key]['category'] = iconv('GBK', 'UTF-8', $value['category']);
            $result[$key]['customer_type'] = iconv('GBK', 'UTF-8', $value['customer_type']);
            $result[$key]['customer_src'] = iconv('GBK', 'UTF-8', $value['customer_src']);
            $result[$key]['customer_category'] = iconv('GBK', 'UTF-8', $value['customer_category']);
            $result[$key]['company'] = iconv('GBK', 'UTF-8', $value['company']);
            $result[$key]['talk_type'] = iconv('GBK', 'UTF-8', $value['talk_type']);
            $result[$key]['company_place'] = iconv('GBK', 'UTF-8', $value['company_place']);
            $result[$key]['customer_trade'] = iconv('GBK', 'UTF-8', $value['customer_trade']);
            $result[$key]['customer_place'] = iconv('GBK', 'UTF-8', $value['customer_place']);
            $result[$key]['salers'] = iconv('GBK', 'UTF-8', $value['salers']);
            $result[$key]['cooper_user'] = iconv('GBK', 'UTF-8', $value['cooper_user']);
            $result[$key]['contact1'] = iconv('GBK', 'UTF-8', $value['contact1']);
            $result[$key]['contact1_job'] = iconv('GBK', 'UTF-8', $value['contact1_job']);
            $result[$key]['customer_address'] = iconv('GBK', 'UTF-8', $value['customer_address']);
            $result[$key]['contact2'] = iconv('GBK', 'UTF-8', $value['contact2']);
            $result[$key]['contact2_job'] = iconv('GBK', 'UTF-8', $value['contact2_job']);
            $result[$key]['customer_all'] = iconv('GBK', 'UTF-8', $value['customer_all']);
            $result[$key]['staff_all'] = iconv('GBK', 'UTF-8', $value['staff_all']);
            $result[$key]['subject'] = iconv('GBK', 'UTF-8', $value['subject']);
            $result[$key]['content1'] = iconv('GBK', 'UTF-8', $value['content1']);
            $result[$key]['content2'] = iconv('GBK', 'UTF-8', $value['content2']);
            $result[$key]['content3'] = iconv('GBK', 'UTF-8', $value['content3']);
            $result[$key]['content4'] = iconv('GBK', 'UTF-8', $value['content4']);
            $result[$key]['report_user'] = iconv('GBK', 'UTF-8', $value['report_user']);
            $result[$key]['creator'] = iconv('GBK', 'UTF-8', $value['creator']);
            $result[$key]['department'] = iconv('GBK', 'UTF-8', $value['department']);
            $result[$key]['talk_place'] = iconv('GBK', 'UTF-8', $value['talk_place']);
            $result[$key]['action_plan'] = iconv('GBK', 'UTF-8', $value['action_plan']);
            $result[$key]['conclusion'] = iconv('GBK', 'UTF-8', $value['conclusion']);
        }
        return $result;
    }

    /*
     *  销售人员洽谈单编辑页面获取详情
     */
    public function travelsalershow($id){
        $result = Db::name('travel_chat')->where([
            'id'=>['=',$id],
            'category'=>['=',iconv('UTF-8', 'GBK','销售')]
        ])->select();
        foreach($result as $key => $value){
            $result[$key]['category'] = iconv('GBK', 'UTF-8', $value['category']);
            $result[$key]['customer_type'] = iconv('GBK', 'UTF-8', $value['customer_type']);
            $result[$key]['customer_src'] = iconv('GBK', 'UTF-8', $value['customer_src']);
            $result[$key]['customer_category'] = iconv('GBK', 'UTF-8', $value['customer_category']);
            $result[$key]['company'] = iconv('GBK', 'UTF-8', $value['company']);
            $result[$key]['talk_type'] = iconv('GBK', 'UTF-8', $value['talk_type']);
            $result[$key]['company_place'] = iconv('GBK', 'UTF-8', $value['company_place']);
            $result[$key]['customer_trade'] = iconv('GBK', 'UTF-8', $value['customer_trade']);
            $result[$key]['customer_place'] = iconv('GBK', 'UTF-8', $value['customer_place']);
            $result[$key]['salers'] = iconv('GBK', 'UTF-8', $value['salers']);
            $result[$key]['cooper_user'] = iconv('GBK', 'UTF-8', $value['cooper_user']);
            $result[$key]['contact1'] = iconv('GBK', 'UTF-8', $value['contact1']);
            $result[$key]['contact1_job'] = iconv('GBK', 'UTF-8', $value['contact1_job']);
            $result[$key]['customer_address'] = iconv('GBK', 'UTF-8', $value['customer_address']);
            $result[$key]['contact2'] = iconv('GBK', 'UTF-8', $value['contact2']);
            $result[$key]['contact2_job'] = iconv('GBK', 'UTF-8', $value['contact2_job']);
            $result[$key]['customer_all'] = iconv('GBK', 'UTF-8', $value['customer_all']);
            $result[$key]['staff_all'] = iconv('GBK', 'UTF-8', $value['staff_all']);
            $result[$key]['subject'] = iconv('GBK', 'UTF-8', $value['subject']);
            $result[$key]['content1'] = iconv('GBK', 'UTF-8', $value['content1']);
            $result[$key]['content2'] = iconv('GBK', 'UTF-8', $value['content2']);
            $result[$key]['content3'] = iconv('GBK', 'UTF-8', $value['content3']);
            $result[$key]['content4'] = iconv('GBK', 'UTF-8', $value['content4']);
            $result[$key]['report_user'] = iconv('GBK', 'UTF-8', $value['report_user']);
            $result[$key]['creator'] = iconv('GBK', 'UTF-8', $value['creator']);
            $result[$key]['department'] = iconv('GBK', 'UTF-8', $value['department']);
            $result[$key]['talk_place'] = iconv('GBK', 'UTF-8', $value['talk_place']);
            $result[$key]['action_plan'] = iconv('GBK', 'UTF-8', $value['action_plan']);
            $result[$key]['conclusion'] = iconv('GBK', 'UTF-8', $value['conclusion']);
        }
        return $result;
    }
    /*
     * 根据id 获取创建人姓名 部门
     */
    public function GetCreateUserByUid($id){
        $result = Db::name('travel_chat')->where('id', '=', $id)->select();
        $uid = $result['0']['creator_id'];
        # 用uid 获取 姓名 部门
        $info = Db::name('new_user')->where('uid','=',$uid)->select();
        $data['uid'] = $uid;
        $data['user_name'] = $info['0']['user_name'];
        $data['department_name'] = $info['0']['department_name'];
        return $data;
    }
    /*
     *
     */
    public function GetApproveStatus($id, $uid, $user_id, $uname, $department){
        $username = GetUserNameByUid($uid);
        $username = str_replace(',','',$username);
        #查询流程
        $approve = Db::name('approval_proces')->where('department_name', 'like', '%'.$department)->select();
        $step1_info = Db::name('new_user')->where('user_name', '=', $approve['0']['step1'])->select();
        $step3_info = Db::name('new_user')->where('user_name', '=', $approve['0']['step3'])->select();
        if($username == $approve['0']['step1']){ // 是否为部门经理提交 --- 是
            $data['to_user_step'] = $approve['0']['step1'];
            $data['to_status_step'] = '1';
            $data['to_uid_step'] = $step1_info['0']['uid'];
            $data['to_user_step1'] = $approve['0']['step2'];
            $data['to_status_step1'] = '0';
            $data['to_uid_step1'] = $this->GetApproveListByName($approve['0']['step2']);
        }else{
            if(iconv('GBK','UTF-8',$approve['0']['step2']) == iconv('GBK','UTF-8',$username)){
                $data['to_user_step1'] = $approve['0']['step2'];
                $data['to_status_step1'] = '1';
                $data['to_uid_step1'] = $this->GetApproveListByName($approve['0']['step2']);
                $data['to_user_step2'] = $approve['0']['step3'];
                $data['to_uid_step2'] = $step3_info['0']['uid'];
            }else{
                $data['to_user_step'] = $approve['0']['step1'];
                $data['to_status_step'] = '0';
                $data['to_uid_step'] = $step1_info['0']['uid'];
            }
        }
        Db::name('travel_chat')->where('id','=',$id)->update($data);
        return true;
    }

    /*
     * 根据姓名获取审批流流程结果
     */
    public function GetApproveListByName($name){
        $result = Db::name('new_user')->where('user_name', '=', $name)->select();
        return $result['0']['uid'];
    }

    public function GetSalerList(){
        $result = Db::name('travel_chat')->select();
        foreach($result as $key => $value){
            $result[$key]['category'] = iconv('GBK', 'UTF-8', $value['category']);
            $result[$key]['customer_type'] = iconv('GBK', 'UTF-8', $value['customer_type']);
            $result[$key]['customer_src'] = iconv('GBK', 'UTF-8', $value['customer_src']);
            $result[$key]['customer_category'] = iconv('GBK', 'UTF-8', $value['customer_category']);
            $result[$key]['company'] = iconv('GBK', 'UTF-8', $value['company']);
            $result[$key]['talk_type'] = iconv('GBK', 'UTF-8', $value['talk_type']);
            $result[$key]['company_place'] = iconv('GBK', 'UTF-8', $value['company_place']);
            $result[$key]['customer_trade'] = iconv('GBK', 'UTF-8', $value['customer_trade']);
            $result[$key]['customer_place'] = iconv('GBK', 'UTF-8', $value['customer_place']);
            $result[$key]['salers'] = iconv('GBK', 'UTF-8', $value['salers']);
            $result[$key]['cooper_user'] = iconv('GBK', 'UTF-8', $value['cooper_user']);
            $result[$key]['contact1'] = iconv('GBK', 'UTF-8', $value['contact1']);
            $result[$key]['contact1_job'] = iconv('GBK', 'UTF-8', $value['contact1_job']);
            $result[$key]['customer_address'] = iconv('GBK', 'UTF-8', $value['customer_address']);
            $result[$key]['contact2'] = iconv('GBK', 'UTF-8', $value['contact2']);
            $result[$key]['contact2_job'] = iconv('GBK', 'UTF-8', $value['contact2_job']);
            $result[$key]['customer_all'] = iconv('GBK', 'UTF-8', $value['customer_all']);
            $result[$key]['staff_all'] = iconv('GBK', 'UTF-8', $value['staff_all']);
            $result[$key]['subject'] = iconv('GBK', 'UTF-8', $value['subject']);
            $result[$key]['content1'] = iconv('GBK', 'UTF-8', $value['content1']);
            $result[$key]['content2'] = iconv('GBK', 'UTF-8', $value['content2']);
            $result[$key]['content3'] = iconv('GBK', 'UTF-8', $value['content3']);
            $result[$key]['content4'] = iconv('GBK', 'UTF-8', $value['content4']);
            $result[$key]['report_user'] = iconv('GBK', 'UTF-8', $value['report_user']);
            $result[$key]['creator'] = iconv('GBK', 'UTF-8', $value['creator']);
            $result[$key]['department'] = iconv('GBK', 'UTF-8', $value['department']);
            $result[$key]['talk_place'] = iconv('GBK', 'UTF-8', $value['talk_place']);
            $result[$key]['action_plan'] = iconv('GBK', 'UTF-8', $value['action_plan']);
            $result[$key]['conclusion'] = iconv('GBK', 'UTF-8', $value['conclusion']);
            $result[$key]['to_user_step'] = iconv('GBK','UTF-8', $value['to_user_step']);
            $result[$key]['to_user_step1'] = iconv('GBK','UTF-8', $value['to_user_step1']);
            $result[$key]['to_user_step2'] = iconv('GBK','UTF-8', $value['to_user_step2']);
            $result[$key]['create_time'] = date('Y-m-d H:i:s', $value['create_time']);
        }
        return $result;
    }

    public function Managetravelsalershow($id){
        $result = Db::name('travel_chat')->where([
            'id'=>['=',$id]
        ])->select();
        foreach($result as $key => $value){
            $result[$key]['category'] = iconv('GBK', 'UTF-8', $value['category']);
            $result[$key]['customer_type'] = iconv('GBK', 'UTF-8', $value['customer_type']);
            $result[$key]['customer_src'] = iconv('GBK', 'UTF-8', $value['customer_src']);
            $result[$key]['customer_category'] = iconv('GBK', 'UTF-8', $value['customer_category']);
            $result[$key]['company'] = iconv('GBK', 'UTF-8', $value['company']);
            $result[$key]['talk_type'] = iconv('GBK', 'UTF-8', $value['talk_type']);
            $result[$key]['company_place'] = iconv('GBK', 'UTF-8', $value['company_place']);
            $result[$key]['customer_trade'] = iconv('GBK', 'UTF-8', $value['customer_trade']);
            $result[$key]['customer_place'] = iconv('GBK', 'UTF-8', $value['customer_place']);
            $result[$key]['salers'] = iconv('GBK', 'UTF-8', $value['salers']);
            $result[$key]['cooper_user'] = iconv('GBK', 'UTF-8', $value['cooper_user']);
            $result[$key]['contact1'] = iconv('GBK', 'UTF-8', $value['contact1']);
            $result[$key]['contact1_job'] = iconv('GBK', 'UTF-8', $value['contact1_job']);
            $result[$key]['customer_address'] = iconv('GBK', 'UTF-8', $value['customer_address']);
            $result[$key]['contact2'] = iconv('GBK', 'UTF-8', $value['contact2']);
            $result[$key]['contact2_job'] = iconv('GBK', 'UTF-8', $value['contact2_job']);
            $result[$key]['customer_all'] = iconv('GBK', 'UTF-8', $value['customer_all']);
            $result[$key]['staff_all'] = iconv('GBK', 'UTF-8', $value['staff_all']);
            $result[$key]['subject'] = iconv('GBK', 'UTF-8', $value['subject']);
            $result[$key]['content1'] = iconv('GBK', 'UTF-8', $value['content1']);
            $result[$key]['content2'] = iconv('GBK', 'UTF-8', $value['content2']);
            $result[$key]['content3'] = iconv('GBK', 'UTF-8', $value['content3']);
            $result[$key]['content4'] = iconv('GBK', 'UTF-8', $value['content4']);
            $result[$key]['report_user'] = iconv('GBK', 'UTF-8', $value['report_user']);
            $result[$key]['creator'] = iconv('GBK', 'UTF-8', $value['creator']);
            $result[$key]['department'] = iconv('GBK', 'UTF-8', $value['department']);
            $result[$key]['talk_place'] = iconv('GBK', 'UTF-8', $value['talk_place']);
            $result[$key]['action_plan'] = iconv('GBK', 'UTF-8', $value['action_plan']);
            $result[$key]['conclusion'] = iconv('GBK', 'UTF-8', $value['conclusion']);
             $result[$key]['create_time'] = date('Y-m-d H:i:s', $value['create_time']);
        }
        return $result;
    }
}

?>